let fs = require("fs");
let persons = fs.readFileSync(__dirname + "/persons.json","utf8")
let user =  { username:"admin1",password:"12345" }
persons = JSON.parse(persons);
let reg = persons.findIndex((item) => {
    return item.username == user.username && item.password == user.password;
})

//判断是否用户已被注册
if (reg == -1) {
    //该用户没有被注册
    console.log("注册成功");
    persons.push(user);//将user加进去
    persons = JSON.stringify(persons);//
    fs.writeFileSync(__dirname + "/persons.json", persons, { flag: "w" })
}
else {
    console.log("已注册");
}